<?php
declare (strict_types = 1);

namespace app\controller;

use app\common\model\Content;
use app\common\model\Headimgurl;
use think\facade\Cache;
use think\facade\Db;
use think\facade\View;
use think\Request;

class Video extends Common
{

    public function __construct()
    {
        parent::__construct();
    }
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {
        //轮播广告


        $where["model_id"] =2;
        $where["status"] =1;
        if(!isset($where)){
            $where = 1;
        }

        $list = \app\common\model\Content::with("v")
            ->where($where)
            ->order("id DESC")
            ->paginate([
                'list_rows' => 15
                ,'query'=> $this->params,
            ]);
        //echo Db::name("article")->getLastSql();die;
        View::assign("list",$list);
        return  view();
    }

    public function read($id)
    {
        $res = Content::with(["images"])->find($id);
        View::assign("res",$res);
        return  view();
    }

    //头像
    public function heads()
    {
        $res = Headimgurl::order("id DESC")
            ->paginate([
                'list_rows' => 15
                ,'query'=> $this->params,
            ]);
        View::assign("list",$res);
        return  view();
    }

    public function head_download($id)
    {
        $res = Headimgurl::find($id);
        // 和上面的下载文件名是一样的效果
        return download(".".$res["headimgurl"], (string)time());
    }

}
